<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            caret-color: transparent;
        }
        body {
            display: flex;
            height: 100vh;
            justify-content: center;
            align-items: center;
        }
        .box1 {
            width: 60%;
            height: 70vh;
            display: flex;
            justify-content: center;
            align-items: center;
            border: 3px #ccc dashed;
        }
        .box2 input {
            padding: 8px 5px;
            background-color: rgb(32, 182, 232);
            color: white;
            border: none;
            border-radius: 5px;
        }
        input:nth-child(1) {
            display: none;
        }
    </style>
</head>
<body>
    <div class="box1">
        <div>
            <img src="./image/addImg.png" alt="">
            <div class="box2">
                <input type="file" value="选择图片" class="choose" multiple/>
                <input type="button" value="选择图片" class="chooseImage">
                <input type="submit" value="提交图片" class="submit"/>
            </div>
        </div>
    </div>
    <script>
        let chooseImage = document.getElementsByClassName("chooseImage")[0];
        let choose = document.getElementsByClassName("choose")[0];
        let submit = document.getElementsByClassName("submit")[0];
        console.log(chooseImage);
        console.log(choose);
        chooseImage.onclick = () => {
            choose.click();
        }
        submit.onclick = () => {
            console.log(choose.files);
            let formData = new FormData();
            for(let i = 0 ; i < choose.files.length ; i++) {
                formData.append(`image${i}`, choose.files[i]);
            }
            // formData.append("image" , choose.files[0]);
            fetch("http:192.168.42.166:3000/upload" , {method: "POST" , body: formData})
                    .then(res => res.json())
                    .then(res => {console.log(res)})
        }
    </script>
</body>
</html>